package fv;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import net.sf.ehcache.Element;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.ferdict.Outfit;

import de.svenjacobs.loremipsum.LoremIpsum;

/**
 * Servlet implementation class comments
 */
public class InitServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public JSONObject json = new JSONObject();
	JSONArray jsonArr = new JSONArray();
	int retcnt = 25;
	String outfitid = null;
	String sqlstr = null;

	public static String[] names = { "my outfit", "Graduation", "Summer",
			"Casual", "Wedding", "Vacation", "First Date", "Interview",
			"Late night out", "Something new", };

	public void init(ServletConfig config) throws ServletException {
		// TODO search folder for images
		System.out.println("######################################");
		int i = 1;
		LoremIpsum li = new LoremIpsum();
		for (String n : names) {
			Outfit o = new Outfit.Builder().name(n).photo(i + ".jpeg").owner(1)
					.outfitId(1).share(true).username("user" + i + "@scu.edu")
					.numDislikes(0).numLikes(0).build();
			List<String> comments = new ArrayList<String>();
			int numCmts = ((int) (Math.random() * 100)) % 5;

			for (int j = 0; j < numCmts; j++) {
				comments.add(li.getWords(((int) (Math.random() * 100)) % 5 + 1));

			}
			o.setCommentList(comments);
			OutfitsDatabase.addOutfit(o);

			i++;
		}

		System.out.println("# initial outfits database size:  "
				+ OutfitsDatabase.getCache().getKeys().size() + " #");
		System.out.println("######################################");

	}

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public InitServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

}
